package drds.server.sqlparser.sqlobject.expression;

import drds.server.sqlparser.visitor.Visitor;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class Between extends AbstractExpression {

	/**
	 * 如果是多表则必须使用表名.字段名的形式进行处理
	 */
	public Expression $;
	private boolean not = false;
	public Expression begin;
	public Expression end;

	public Between() {

	}

	public Between(Expression $, Expression begin, Expression end) {
		set$($);
		setBegin(begin);
		setEnd(end);
	}

	public Between(Expression $, boolean not, Expression begin, Expression end) {
		this($, begin, end);
		this.not = not;
	}

	public void set$(Expression $) {
		if ($ != null) {
			$.setParent(this);
		}
		this.$ = $;
	}

	public Expression get$() {
		return this.$;
	}

	public void setNot(boolean not) {
		this.not = not;
	}

	public boolean isNot() {
		return this.not;
	}

	public void setBegin(Expression begin) {
		if (begin != null) {
			begin.setParent(this);
		}
		this.begin = begin;
	}

	public Expression getBegin() {
		return this.begin;
	}

	public void setEnd(Expression end) {
		if (end != null) {
			end.setParent(this);
		}
		this.end = end;
	}

	public Expression getEnd() {
		return this.end;
	}

	protected void accept0(Visitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.$);
			acceptChild(visitor, this.begin);
			acceptChild(visitor, this.end);
		}
		visitor.endVisit(this);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((begin == null) ? 0 : begin.hashCode());
		result = prime * result + ((end == null) ? 0 : end.hashCode());
		result = prime * result + (not ? 1231 : 1237);
		result = prime * result + (($ == null) ? 0 : $.hashCode());

		return result;

	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null) {
			return false;
		}
		if (getClass() != o.getClass()) {
			return false;
		}
		Between other = (Between) o;
		if (begin == null) {
			if (other.begin != null) {
				return false;
			}
		} else if (!begin.equals(other.begin)) {
			return false;
		}
		if (end == null) {
			if (other.end != null) {
				return false;
			}
		} else if (!end.equals(other.end)) {
			return false;
		}
		if (not != other.not) {
			return false;
		}
		if ($ == null) {
			if (other.$ != null) {
				return false;
			}
		} else if (!$.equals(other.$)) {
			return false;
		}
		return true;
	}
}
